<!--短信模板-->
<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState">
			<a-row :gutter="24">
				<a-col :span="5">
					<a-form-item label="模版名称：" name="templateName">
						<a-input v-model:value="searchFormState.templateName" placeholder="请输入模版名称" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="4">
					<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card :bordered="false" class="mt-2">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
			:scroll="{ x: 'max-content' }"
			:tool-config="{ refresh: true, height: true, columnSetting: false, striped: false }"
		>
			<template #operator>
				<a-space v-if="hasPerm('smsTemplateButton')">
					<a-button type="primary" @click="formRef.onOpen()" style="margin-right: 10%">
						<template #icon>
							<plus-outlined />
						</template>
						新增
					</a-button>
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'action' && hasPerm('smsTemplateButton')">
					<a-space>
						<a @click="formRef.onOpen(record)">编辑</a>
						<a-divider type="vertical" />
						<a-popconfirm title="确定要删除此公司吗？" @confirm="deleteModule(record.id)">
							<a-button type="link" danger size="small">删除</a-button>
						</a-popconfirm>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="tableRef.refresh(true)" />
</template>

<script setup name="smsTemplate">
	import Form from '@/views/tjzy/sms/template/form.vue'
	import smsTemplateApi from '@/api/tjzy/sms/smsTemplateApi'
	import UserSelect from '@/components/XnUserSelector/userSelect.vue'

	const searchFormState = ref({})
	const tableRef = ref()
	const formRef = ref()
	const columns = [
		{
			title: '模版名称',
			dataIndex: 'templateName'
		},
		{
			title: '模版编码',
			dataIndex: 'templateCode'
		},
		{
			title: '模版内容',
			dataIndex: 'templateContent',
			width: '1000px'
		},
		// {
		// 	title: '供应商优先级',
		// 	dataIndex: 'supplierOrder'
		// },
		{
			title: '创建人',
			dataIndex: 'createUserName'
		},
		{
			title: '创建时间',
			dataIndex: 'createTime'
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center'
		}
	]
	const loadData = (parameter) => {
		searchFormState.value.current = parameter.current
		searchFormState.value.size = parameter.size
		return smsTemplateApi.pageList(searchFormState.value).then((res) => {
			return res
		})
	}
	const deleteModule = (id) => {
		smsTemplateApi.del(id).then((res) => {
			tableRef.value.refresh(true)
		})
	}
</script>
